#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>

using func_t = std::function<void()>;

int gcount = 0;
std::vector<func_t> gfuncs;

void handler(int signo)
{
    for(auto& f : gfuncs)
    {
        f();
    }
    std::cout << "gcount : " << gcount << std::endl;
    alarm(1);
}

int main()
{
    gfuncs.push_back([](){
        std::cout << "我是一个日志任务" << std::endl;
    });
    gfuncs.push_back([](){
        std::cout << "我是一个下载任务" << std::endl;
    });
    gfuncs.push_back([](){
        std::cout << "我是一个mysql任务" << std::endl;
    });
    alarm(1);
    signal(SIGALRM,handler);
    while(true)
    {
        pause();
        std::cout << "我醒来了..." << std::endl;
        gcount++;
    }
    return 0;
}
